package com.hongkou.tvstation.common.vo;

public class PageVO {
	private static int pageSize = 20;
	private Long pageNum;
	private Long totalRecords;
	private Long totalPages;
	private Long startFrom;

	public Long getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(Long totalPages) {
		this.totalPages = totalPages;
	}

	public int getPageSize() {
		return pageSize;
	}

	public Long getPageNum() {
		return pageNum;
	}

	public PageVO setPageNum(Long pageNum) {
		this.pageNum = pageNum;
		calcPageDisplay();
		return this;
	}

	private void calcPageDisplay() {
		if (pageNum == null || pageNum == 0)
			pageNum = 1L;
		startFrom = (pageNum - 1) * pageSize;
	}

	public Long getTotalRecords() {
		return totalRecords;
	}

	public void setTotalRecords(Long totalRecords) {
		this.totalRecords = totalRecords;
		calcTotalPages();
	}

	private void calcTotalPages() {
		setTotalPages((totalRecords - 1)
				/ pageSize
				+ (new Double(Math.floor((totalRecords - 1) % pageSize))
						.longValue() > 0 ? 1L : 0L));
	}

	public Long getStartFrom() {
		if (startFrom == null)
			setPageNum(1L);
		return startFrom;
	}

	public void setStartFrom(Long startFrom) {
		this.startFrom = startFrom;
	}

}
